package thread;

import java.util.concurrent.CountDownLatch;

/**
 * @Author zhangxuhui
 * @Date 2023/12/21
 * @email zxh_1633@163.com 38796 38288 6576 6797
 */
public class CacheLine {
    private static final int NUM = 10_0000_0000;

    private static class T{
        private long t1,t2,t3,t4,t5,t6,t7;
        private volatile long l = 0L;
        private long tt1,tt2,tt3,tt4,tt5,tt6,tt7;
    }

    public static T[] ts = new T[2];

    static {
        ts[0] = new T();
        ts[1] = new T();
    }

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(2);

        long satrtTime = System.currentTimeMillis();

        Thread th1 = new Thread("thread-1"){
            @Override
            public void run() {
                for(int i=0;i<NUM;i++){
                    ts[0].l = i;
                }
                latch.countDown();
            }
        };
        Thread th2 = new Thread("thread-2"){
            @Override
            public void run() {
                for(int i=0;i<NUM;i++){
                    ts[1].l = i;
                }
                latch.countDown();
            }
        };
        th1.start();
        th2.start();

        latch.await();

        long endTime = System.currentTimeMillis();
        System.out.println(endTime-satrtTime);
    }
}
